import {useNavigate, useSearchParams} from 'react-router-dom';

const GetUserInfo = () => {
    const [params] = useSearchParams();
    const navigate = useNavigate();
    const authCode = params.get("authCode");
    const myHeaders = new Headers();
    myHeaders.append("Content-Type", "application/json");

    const requestOptions = {
        method: 'GET',
        headers: myHeaders,
        redirect: 'follow'
    };

    fetch(`${window.appConfig.servicePath}/auth?authCode=${authCode}`, requestOptions)
        .then(response => response.json()
            .then(result => {
                console.log("result", result)
                localStorage.setItem("icip-dingtalk-loginUser", JSON.stringify(result.loginUser))
                localStorage.setItem("icip-dingtalk-corpId", result.corpId)
                navigate("/home/project")
            }))
        .catch(error => console.log('error', error));
    return;
};

export default GetUserInfo;